package cn.school.controller.studentLeaveInfo;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.exception.ApiException;


import cn.school.student.service.StudentLeaveReportService;
import cn.school.student.vo.StudentLeaveInfoVo;
import cn.school.workflow.service.LeaveApplyService;
import cn.school.workflow.service.StudentLeaveStatisticsService;
import cn.school.workflow.vo.LeaveApplyVO;
import cn.school.workflow.vo.StudentLeaveApplyVO;
import cn.school.workflow.vo.StudentLeaveStatisticsVo;
import cn.school.workflow.vo.WorkFlowVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/studentLeave")
@RestController
public class StudentsTakeController {
    @Autowired
    private LeaveApplyService leaveApplyService;
    @Autowired
    private StudentLeaveReportService studentLeaveReportService;

    @PostMapping("/pageList")
   public CommonResult findLeaveApplyPageList(@RequestBody StudentLeaveApplyVO vo){
       IPage<StudentLeaveApplyVO> pageList =  studentLeaveReportService.pagelist(vo);
       return  CommonResult.success(CommonPage.restPage(pageList));
   }
    @PostMapping("/create")
    public CommonResult<Integer> createLeaveApply(@RequestBody LeaveApplyVO  vo) throws ApiException {
        int flag =  leaveApplyService.createLeaveApply(vo);
        if(flag>0){
            return CommonResult.success();
        }
        return  CommonResult.failed("流程创建失败");
    }

    @PostMapping("/cancelLeaveApply")
    @PreAuthorize("@ss.hasPermi('leave:apply:cancel')")
    public CommonResult<CommonPage<LeaveApplyVO>> cancelLeaveApply(@RequestBody WorkFlowVO vo) throws ApiException{
        boolean flag =  leaveApplyService.cancelLeaveApply(vo);
        if(flag){
            return CommonResult.success();
        }
        return  CommonResult.failed("流程取消失败");
    }
}
